package com.ajk.server.controller.events;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import com.ajk.server.service.AjkAccountService;
import com.ajk.server.service.NurseStationDictService;
import com.ajk.server.service.PatientEventService;

@Component
public class RemoteSyncListener implements ApplicationListener<RemoteSyncEvent>{
	@Autowired
	NurseStationDictService nurseStationDictService;
	
	@Autowired
	AjkAccountService ajkAccountService;
	
	@Autowired
	PatientEventService patientEventService;
	
	@Override
	public void onApplicationEvent(RemoteSyncEvent event) {
		int type = event.getType();
		switch (type) {
		case RemoteSyncEvent.SYNC_NURSE_STATION:
			
			Integer nurseStationId = (Integer) event.getSource();
			
			nurseStationDictService.syncInRemote(nurseStationId);
			
			break;
		case RemoteSyncEvent.SYNC_USER:
			
			Integer userId = (Integer) event.getSource();
			
			ajkAccountService.syncInRemote(userId);
			
			break;
		case RemoteSyncEvent.SYNC_HEALTHY_DATA:
			Integer peId = (Integer) event.getSource();
			patientEventService.syncInRemote(peId);
			break;
		default:
			break;
		}
	}

}
